service= {

    register: function () {
        var register_user = $("#register_user").val();
        if(register_user == ""){
            alert("用户名不能为空");
            return false;
        }

        var register_password = $("#register_password").val();
        if(register_password == ""){
            alert("密码不能为空");
            return false;
        }
        var register_confirm = $("#register_confirm").val();
        if(register_confirm == ""){
            alert("请确认密码");
            return false;
        }
        if(register_confirm != register_password){
            alert("两次输入不一致，请重新输入");
            return false;
        }
        register_password = hex_md5(register_password);
        var user = {"username":register_user,"password":register_password};
        interface.user.register(user, function (data) {
            alert("注册成功");
            window.location.href = "/homepage"
        });

    },

    login: function () {
        var login_user = $("#login_user").val();
        if(login_user == ""){
            alert("用户名不能为空");
            return false;
        }

        var login_password = $("#login_password").val();
        if(login_password == ""){
            alert("密码不能为空");
            return false;
        }
        login_password = hex_md5(login_password);
        var user = {"username":login_user,"password":login_password};
        interface.user.login(user, function (data) {
            console.log(data)
            if(data.flag){
                window.localStorage.setItem("userid",data.data.userid);
                window.localStorage.setItem("token",data.data.token);
                window.location.href = "/"
            }else{
                alert(data.message);
            }
        });

    },


}